﻿#include "function_measureElectrode.h"
//OpenCV MatתHalcon HObject

MeasureElectrode::MeasureElectrode(QDialog* parent, QSettings* qsettings, QString section) : QDialog(parent)
{
    m_qsettings = qsettings;
    m_section = section;

    //m_model_image_path = QCoreApplication::applicationDirPath() + "/" + m_model_image_path;

    this->setWindowTitle(("电极测量"));
    QRect desktop_rect = QApplication::desktop()->geometry();
    double ratio_x = desktop_rect.width()/1920.0;
    double ratio_y = desktop_rect.height()/1080.0;

    move(0,0);
    setFixedSize(1920*ratio_x,1010*ratio_y);

    m_view = new MyQGraphicsView(this);
    m_view->setGeometry(660 * ratio_x, 0, 1000 * 1.25 * ratio_x, 800 * 1.25 * ratio_y);

    QSize control_size(150*ratio_x,40*ratio_y);

    QWidget* p = new QWidget(this);
    p->move(0*ratio_x,0*ratio_y);
    p->setFixedSize(600*ratio_x,900*ratio_y);

    QGridLayout *qgridLayout = new QGridLayout();
    p->setLayout(qgridLayout);

    int index = 0;

    QSize ButtonSize(160 * ratio_x, 40 * ratio_y);

  

    m_qlabel_row1_offset = new QLabel();
    m_qlabel_row1_offset->setText("电极测量上缩进");
    m_qlabel_row1_offset->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_row1_offset, index, 0);
    m_SpinBox_row1_offset = new QSpinBox();
    m_SpinBox_row1_offset->setFixedSize(control_size);
    m_SpinBox_row1_offset->setMinimum(0);
    m_SpinBox_row1_offset->setMaximum(100);
    qgridLayout->addWidget(m_SpinBox_row1_offset, index, 1);
    
    index++;
    m_qlabel_row2_offset = new QLabel();
    m_qlabel_row2_offset->setText("电极测量下缩进");
    m_qlabel_row2_offset->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_row2_offset, index, 0);
    m_SpinBox_row2_offset = new QSpinBox();
    m_SpinBox_row2_offset->setFixedSize(control_size);
    m_SpinBox_row2_offset->setMinimum(0);
    m_SpinBox_row2_offset->setMaximum(100);
    qgridLayout->addWidget(m_SpinBox_row2_offset, index, 1);
    
    index++;
    m_qlabel_column1_offset = new QLabel();
    m_qlabel_column1_offset->setText("电极测量左缩进");
    m_qlabel_column1_offset->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_column1_offset,index,0);
    m_SpinBox_column1_offset = new QSpinBox();
    m_SpinBox_column1_offset->setFixedSize(control_size);
    m_SpinBox_column1_offset->setMinimum(0);
    m_SpinBox_column1_offset->setMaximum(100);
    qgridLayout->addWidget(m_SpinBox_column1_offset, index, 1);


    index++;
    m_qlabel_column2_offset = new QLabel();
    m_qlabel_column2_offset->setText("电极测量右缩进");
    m_qlabel_column2_offset->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_column2_offset,index,0);
    m_SpinBox_column2_offset = new QSpinBox();
    m_SpinBox_column2_offset->setFixedSize(control_size);
    m_SpinBox_column2_offset->setMinimum(0);
    m_SpinBox_column2_offset->setMaximum(100);
    qgridLayout->addWidget(m_SpinBox_column2_offset, index, 1);

    index++;
    m_qlabel_measure_number = new QLabel();
    m_qlabel_measure_number->setText("扫描次数");
    m_qlabel_measure_number->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_measure_number,index,0);
    m_SpinBox_measure_number = new QSpinBox();
    m_SpinBox_measure_number->setFixedSize(control_size);
    m_SpinBox_measure_number->setMinimum(0);
    m_SpinBox_measure_number->setMaximum(99);
    qgridLayout->addWidget(m_SpinBox_measure_number, index, 1);
    index++;

    m_qlabel_left_width_low = new QLabel();
    m_qlabel_left_width_low->setText("左电极宽度最小值");
    m_qlabel_left_width_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_left_width_low, index, 0);
    m_QDoubleSpinBox_left_width_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_left_width_low->setFixedSize(control_size);
    m_QDoubleSpinBox_left_width_low->setMinimum(0);
    m_QDoubleSpinBox_left_width_low->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_left_width_low, index, 1);

    index++;
    m_qlabel_left_width_high = new QLabel();
    m_qlabel_left_width_high->setText("左电极宽度最大值");
    m_qlabel_left_width_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_left_width_high, index, 0);
    m_QDoubleSpinBox_left_width_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_left_width_high->setFixedSize(control_size);
    m_QDoubleSpinBox_left_width_high->setMinimum(0);
    m_QDoubleSpinBox_left_width_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_left_width_high, index, 1);
    index++;

    m_qlabel_left_height_low = new QLabel();
    m_qlabel_left_height_low->setText("左电极高度最小值");
    m_qlabel_left_height_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_left_height_low, index, 0);
    m_QDoubleSpinBox_left_height_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_left_height_low->setFixedSize(control_size);
    m_QDoubleSpinBox_left_height_low->setMinimum(0);
    m_QDoubleSpinBox_left_height_low->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_left_height_low, index, 1);
    index++;

    m_qlabel_left_height_high = new QLabel();
    m_qlabel_left_height_high->setText("左电极高度最大值");
    m_qlabel_left_height_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_left_height_high, index, 0);
    m_QDoubleSpinBox_left_height_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_left_height_high->setFixedSize(control_size);
    m_QDoubleSpinBox_left_height_high->setMinimum(0);
    m_QDoubleSpinBox_left_height_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_left_height_high, index, 1);
    index++;

    m_qlabel_right_width_low = new QLabel();
    m_qlabel_right_width_low->setText("右电极宽度最小值");
    m_qlabel_right_width_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_right_width_low, index, 0);
    m_QDoubleSpinBox_right_width_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_right_width_low->setFixedSize(control_size);
    m_QDoubleSpinBox_right_width_low->setMinimum(0);
    m_QDoubleSpinBox_right_width_low->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_right_width_low, index, 1);

    index++;
    m_qlabel_right_width_high = new QLabel();
    m_qlabel_right_width_high->setText("右电极宽度最大值");
    m_qlabel_right_width_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_right_width_high, index, 0);
    m_QDoubleSpinBox_right_width_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_right_width_high->setFixedSize(control_size);
    m_QDoubleSpinBox_right_width_high->setMinimum(0);
    m_QDoubleSpinBox_right_width_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_right_width_high, index, 1);
    index++;

    m_qlabel_right_height_low = new QLabel();
    m_qlabel_right_height_low->setText("右电极高度最小值");
    m_qlabel_right_height_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_right_height_low, index, 0);
    m_QDoubleSpinBox_right_height_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_right_height_low->setFixedSize(control_size);
    m_QDoubleSpinBox_right_height_low->setMinimum(0);
    m_QDoubleSpinBox_right_height_low->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_right_height_low, index, 1);
    index++;

    m_qlabel_right_height_high = new QLabel();
    m_qlabel_right_height_high->setText("右电极高度最大值");
    m_qlabel_right_height_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_right_height_high, index, 0);
    m_QDoubleSpinBox_right_height_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_right_height_high->setFixedSize(control_size);
    m_QDoubleSpinBox_right_height_high->setMinimum(0);
    m_QDoubleSpinBox_right_height_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_right_height_high, index, 1);
    index++;

    m_qlabel_total_width_low = new QLabel();
    m_qlabel_total_width_low->setText("本体宽度最小值");
    m_qlabel_total_width_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_total_width_low, index, 0);
    m_QDoubleSpinBox_total_width_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_total_width_low->setFixedSize(control_size);
    m_QDoubleSpinBox_total_width_low->setMinimum(0);
    m_QDoubleSpinBox_total_width_low->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_total_width_low, index, 1);

    index++;
    m_qlabel_total_width_high = new QLabel();
    m_qlabel_total_width_high->setText("本体宽度最大值");
    m_qlabel_total_width_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_total_width_high, index, 0);
    m_QDoubleSpinBox_total_width_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_total_width_high->setFixedSize(control_size);
    m_QDoubleSpinBox_total_width_high->setMinimum(0);
    m_QDoubleSpinBox_total_width_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_total_width_high, index, 1);
    index++;

    m_qlabel_total_height_low = new QLabel();
    m_qlabel_total_height_low->setText("本体高度最小值");
    m_qlabel_total_height_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_total_height_low, index, 0);
    m_QDoubleSpinBox_total_height_low = new QDoubleSpinBox();
    m_QDoubleSpinBox_total_height_low->setFixedSize(control_size);
    m_QDoubleSpinBox_total_height_low->setMinimum(0);
    m_QDoubleSpinBox_total_height_low->setMaximum(1000);
    qgridLayout->addWidget(m_QDoubleSpinBox_total_height_low, index, 1);

    index++;
    m_qlabel_total_height_high = new QLabel();
    m_qlabel_total_height_high->setText("本体高度最大值");
    m_qlabel_total_height_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_total_height_high, index, 0);
    m_QDoubleSpinBox_total_height_high = new QDoubleSpinBox();
    m_QDoubleSpinBox_total_height_high->setFixedSize(control_size);
    m_QDoubleSpinBox_total_height_high->setMinimum(0);
    m_QDoubleSpinBox_total_height_high->setMaximum(10000);
    qgridLayout->addWidget(m_QDoubleSpinBox_total_height_high, index, 1);

    index++;
    m_qlabel_ratio = new QLabel();
    m_qlabel_ratio->setText("测量比例");
    m_qlabel_ratio->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_ratio, index, 0);
    m_qdoublespinbox_ratio = new QDoubleSpinBox ();
    m_qdoublespinbox_ratio->setFixedSize(control_size);
    m_qdoublespinbox_ratio->setDecimals(5);
    m_qdoublespinbox_ratio->setMinimum(0.00001);
    m_qdoublespinbox_ratio->setMaximum(10000);
    qgridLayout->addWidget(m_qdoublespinbox_ratio, index, 1);


    index++;
    m_pushbutton_save_parameter = new QPushButton(this);
    m_pushbutton_save_parameter->setFixedSize(control_size);
    m_pushbutton_save_parameter->setText("保存参数");
    connect(m_pushbutton_save_parameter, &QPushButton::clicked, this, &MeasureElectrode::saveParameter);
    qgridLayout->addWidget(m_pushbutton_save_parameter, index,0);

    index++;
    m_pushbutton_detection = new QPushButton(this);
    m_pushbutton_detection->setFixedSize(control_size);
    m_pushbutton_detection->setText("检测");
    connect(m_pushbutton_detection, &QPushButton::clicked, this, &MeasureElectrode::detectionImage);
    qgridLayout->addWidget(m_pushbutton_detection, index,0);
    
    index++;
    m_pushbutton_return = new QPushButton(this);
    m_pushbutton_return->setFixedSize(control_size);
    m_pushbutton_return->setText("退出");
    qgridLayout->addWidget(m_pushbutton_return, index, 0);
    connect(m_pushbutton_return, &QPushButton::clicked, this, [=]() {
        this->hide();
        });

    
    try
    {
        m_proc_detection = new HDevProcedure("measureElectrode");
        m_call_detection = new HDevProcedureCall(*m_proc_detection);
    }
    catch (HDevEngineException& hdev_exception)
    {
        //QMessageBox::information(nullptr, "", hdev_exception.Message());
    }


    loadParameter();
}

MeasureElectrode::~MeasureElectrode()
{
    ;
}

bool MeasureElectrode::detection( HObject image_in, QString& message)
{
    try
    {
        // Set the input parameters of the procedure
        if (!region.IsInitialized())
        {
            return false;
        }
        m_call_detection->SetInputIconicParamObject("image", image_in);
        m_call_detection->SetInputIconicParamObject("region", region);

        m_call_detection->SetInputCtrlParamTuple("row1_offset", row1_offset);
        m_call_detection->SetInputCtrlParamTuple("column1_offset", column1_offset);
        m_call_detection->SetInputCtrlParamTuple("row2_offset", row2_offset);
        m_call_detection->SetInputCtrlParamTuple("column2_offset", column2_offset);
        m_call_detection->SetInputCtrlParamTuple("measure_number", measure_number);
//        if(m_ratio==0)
//        {
//            m_ratio=1;
//        }
//        m_call_detection->SetInputCtrlParamTuple("height_low", (int)(height_low/m_ratio));
//        m_call_detection->SetInputCtrlParamTuple("height_high", (int)(height_high/m_ratio));
//        m_call_detection->SetInputCtrlParamTuple("width_low", (int)(width_low/m_ratio));
//        m_call_detection->SetInputCtrlParamTuple("width_high",(int)( width_high/m_ratio));



        // Execute the procedure

//       HDevEngine().StartDebugServer();
//        m_call_detection->SetWaitForDebugConnection(true);
        m_call_detection->Execute();
//        HDevEngine().StopDebugServer();

        region_height_show = m_call_detection->GetOutputIconicParamObject("region_height_show");
        region_width_show = m_call_detection->GetOutputIconicParamObject("region_width_show");

        // get the output parameters
        HTuple ret = m_call_detection->GetOutputCtrlParamTuple(1);
        HTuple msg = m_call_detection->GetOutputCtrlParamTuple(2);
        HTuple total_width  = m_call_detection->GetOutputCtrlParamTuple(3);
        HTuple total_height = m_call_detection->GetOutputCtrlParamTuple(4);
        HTuple htuple_height_low  = m_call_detection->GetOutputCtrlParamTuple(5);
        HTuple htuple_height_high = m_call_detection->GetOutputCtrlParamTuple(6);
        HTuple htuple_width_low  = m_call_detection->GetOutputCtrlParamTuple(7);
        HTuple htuple_width_high = m_call_detection->GetOutputCtrlParamTuple(8);

        m_result = ret[0].I();

        if(m_result!=1)
        {
            message += msg[0].S();
            return false;
        }
        else
        {
            m_total_height = total_height[0].I();
            m_total_width =  total_width[0].I();   

            int height_low_left = htuple_height_low[0].I();
            int height_high_left= htuple_height_high[0].I();
            int width_low_left  = htuple_width_low[0].I();
            int width_high_left = htuple_width_high[0].I();

            int height_low_right = htuple_height_low[1].I();
            int height_high_right= htuple_height_high[1].I();
            int width_low_right  = htuple_width_low[1].I();
            int width_high_right = htuple_width_high[1].I();


//            int height_low_now = min(height_low_left,height_low_right);
//            int height_high_now = max(height_high_left,height_high_right);
//            int width_low_now = min(width_low_left,width_low_right);
//            int width_high_now = max(width_high_left,width_high_right);

           /* message +=" 本体高度" + QString::number(m_total_height*m_ratio) +" 本体宽度" + QString::number(m_total_width*m_ratio) +"\n";
            message +=" 左电极高度最小值" + QString::number(height_low_left*m_ratio) ;
            message +=" 高度最大值" + QString::number(height_high_left*m_ratio) ;
			message += " 宽度最小值" + QString::number(width_low_left*m_ratio);
			message += " 宽度最大值" + QString::number(width_high_left*m_ratio) + "\n";
           

			message += " 右电极高度最小值" + QString::number(height_low_right*m_ratio) ;
			message += " 高度最大值" + QString::number(height_high_right*m_ratio);
            message +=" 宽度最小值" + QString::number(width_low_right*m_ratio) ;
            message +=" 宽度最大值" + QString::number(width_high_right*m_ratio) + "\n";*/

            if(m_total_width*m_ratio<= total_width_low || m_total_width*m_ratio>= total_width_high)
            {
                 message +=  "NG 本体宽度超出标准 本体宽度:" + QString::number(m_total_width*m_ratio);
                 return false;
            }
            if(m_total_height*m_ratio<= total_height_low || m_total_height*m_ratio>= total_height_high)
            {
                 message +=  "NG 本体高度超出标准 本体高度:" + QString::number(m_total_height*m_ratio);
                 return false;
            }

            if(height_low_left*m_ratio<= left_height_low)
            {
                 message +=  "NG 左电极高度最小值超出标准 电极高度:" + QString::number(height_low_left*m_ratio);
                 return false;
            }
            if(height_low_right*m_ratio<= right_height_low)
            {
                message +=  "NG 右电极高度最小值超出标准 电极高度:" + QString::number(height_low_right*m_ratio);
                return false;
            }
            if(height_high_left*m_ratio>= left_height_high)
            {
                 message +=  "NG 左电极高度最大值超出标准 电极高度:" + QString::number(height_high_left*m_ratio);
                 return false;
            }
            if(height_high_right*m_ratio>= right_height_high)
            {
                 message +=  "NG 右电极高度最大值超出标准 电极高度:" + QString::number(height_high_right*m_ratio);
                 return false;
            }
            if(width_low_left*m_ratio<= left_width_low)
            {
                 message +=  "NG 左电极宽度最小值超出标准 电极宽度:" + QString::number(width_low_left*m_ratio);
                 return false;
            }
            if(width_low_right*m_ratio<= right_width_low)
            {
                 message +=  "NG 右电极宽度最小值超出标准 电极宽度:" + QString::number(width_low_right*m_ratio);
                 return false;
            }
            if(width_high_left*m_ratio>= left_width_high)
            {
                 message +=  "NG 左电极宽度最大值超出标准 电极宽度:" + QString::number(width_high_left*m_ratio);
                 return false;
            }
            if(width_high_right*m_ratio>= right_width_high)
            {
                 message +=  "NG 右电极宽度最大值超出标准 电极宽度:" + QString::number(width_high_right*m_ratio);
                 return false;
            }


        }

        return true;
    }
    catch (HDevEngineException& hdev_exception)
    {
        message = hdev_exception.Message();
        return false;
    }
  
    return true;
}

void MeasureElectrode::detectionImage()
{
    Mat image_show = himageToMat(image_in);
    if(image_show.empty())
    {
        //QMessageBox::information(nullptr,"","没有图像");
        return;
    }
    QString message;
    detection(image_in,message);



    draw(image_show, image_show);

    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image, message);
}

void MeasureElectrode::draw(Mat image_in,Mat& image_out)
{
    if(image_in.empty())
        return;
//    image_out = drawRegion(image_in, region, Scalar(0, 255, 0));
    image_out = drawRegion(image_out, region_height_show, Scalar(0, 255, 0));
    //GenEmptyRegion(&region);
    GenEmptyRegion(&region_height_show);
    image_out = drawRegion(image_out, region_width_show, Scalar(0, 255, 0));
    //GenEmptyRegion(&region);
    GenEmptyRegion(&region_width_show);
}

void MeasureElectrode::loadParameter()
{
    row1_offset = m_qsettings->value(m_section + "/" + "row1_offset").toInt();
    column1_offset = m_qsettings->value(m_section + "/" + "column1_offset").toInt();
    row2_offset = m_qsettings->value(m_section + "/" + "row2_offset").toInt();
    column2_offset = m_qsettings->value(m_section + "/" + "column2_offset").toInt();
    measure_number = m_qsettings->value(m_section + "/" + "measure_number").toInt();
    left_height_low = m_qsettings->value(m_section + "/" + "left_height_low").toDouble();
    left_height_high = m_qsettings->value(m_section + "/" + "left_height_high").toDouble();
    left_width_low = m_qsettings->value(m_section + "/" + "left_width_low").toDouble();
    left_width_high = m_qsettings->value(m_section + "/" + "left_width_high").toDouble();
    right_height_low = m_qsettings->value(m_section + "/" + "right_height_low").toDouble();
    right_height_high = m_qsettings->value(m_section + "/" + "right_height_high").toDouble();
    right_width_low = m_qsettings->value(m_section + "/" + "right_width_low").toDouble();
    right_width_high = m_qsettings->value(m_section + "/" + "right_width_high").toDouble();
    total_height_low = m_qsettings->value(m_section + "/" + "total_height_low").toDouble();
    total_height_high = m_qsettings->value(m_section + "/" + "total_height_high").toDouble();
    total_width_low = m_qsettings->value(m_section + "/" + "total_width_low").toDouble();
    total_width_high = m_qsettings->value(m_section + "/" + "total_width_high").toDouble();
    m_ratio    = m_qsettings->value(m_section + "/" + "m_ratio",1).toDouble();

    m_SpinBox_row1_offset->setValue(row1_offset);
    m_SpinBox_column1_offset->setValue(column1_offset);
    m_SpinBox_row2_offset->setValue(row2_offset);
    m_SpinBox_column2_offset->setValue(column2_offset);
    m_SpinBox_measure_number->setValue(measure_number);
    m_QDoubleSpinBox_left_height_low->setValue(left_height_low);
    m_QDoubleSpinBox_left_height_high->setValue(left_height_high);
    m_QDoubleSpinBox_left_width_low->setValue(left_width_low);
    m_QDoubleSpinBox_left_width_high->setValue(left_width_high);
    m_QDoubleSpinBox_right_height_low->setValue(right_height_low);
    m_QDoubleSpinBox_right_height_high->setValue(right_height_high);
    m_QDoubleSpinBox_right_width_low->setValue(right_width_low);
    m_QDoubleSpinBox_right_width_high->setValue(right_width_high);
    m_QDoubleSpinBox_total_height_low->setValue(total_height_low);
    m_QDoubleSpinBox_total_height_high->setValue(total_height_high);
    m_QDoubleSpinBox_total_width_low->setValue(total_width_low);
    m_QDoubleSpinBox_total_width_high->setValue(total_width_high);
    m_qdoublespinbox_ratio->setValue(m_ratio);
    return ;
}

void MeasureElectrode::saveParameter()
{
    row1_offset = m_SpinBox_row1_offset->value();
    column1_offset = m_SpinBox_column1_offset->value();
    row2_offset = m_SpinBox_row2_offset->value();
    column2_offset = m_SpinBox_column2_offset->value();
    measure_number = m_SpinBox_measure_number->value();
    left_height_low = m_QDoubleSpinBox_left_height_low->value();
    left_height_high = m_QDoubleSpinBox_left_height_high->value();
    left_width_low = m_QDoubleSpinBox_left_width_low->value();
    left_width_high = m_QDoubleSpinBox_left_width_high->value();
    right_height_low = m_QDoubleSpinBox_right_height_low->value();
    right_height_high = m_QDoubleSpinBox_right_height_high->value();
    right_width_low = m_QDoubleSpinBox_right_width_low->value();
    right_width_high = m_QDoubleSpinBox_right_width_high->value();
    total_height_low = m_QDoubleSpinBox_total_height_low->value();
    total_height_high = m_QDoubleSpinBox_total_height_high->value();
    total_width_low = m_QDoubleSpinBox_total_width_low->value();
    total_width_high = m_QDoubleSpinBox_total_width_high->value();
    m_ratio = m_qdoublespinbox_ratio->value();


    m_qsettings->setValue(m_section + "/" + "row1_offset", row1_offset);
    m_qsettings->setValue(m_section + "/" + "column1_offset", column1_offset);
    m_qsettings->setValue(m_section + "/" + "row2_offset", row2_offset);
    m_qsettings->setValue(m_section + "/" + "column2_offset", column2_offset);
    m_qsettings->setValue(m_section + "/" + "measure_number", measure_number);
    m_qsettings->setValue(m_section + "/" + "left_height_low", left_height_low);
    m_qsettings->setValue(m_section + "/" + "left_height_high", left_height_high);
    m_qsettings->setValue(m_section + "/" + "left_width_low", left_width_low);
    m_qsettings->setValue(m_section + "/" + "left_width_high", left_width_high);
    m_qsettings->setValue(m_section + "/" + "right_height_low", right_height_low);
    m_qsettings->setValue(m_section + "/" + "right_height_high", right_height_high);
    m_qsettings->setValue(m_section + "/" + "right_width_low", right_width_low);
    m_qsettings->setValue(m_section + "/" + "right_width_high", right_width_high);
    m_qsettings->setValue(m_section + "/" + "total_height_low", total_height_low);
    m_qsettings->setValue(m_section + "/" + "total_height_high", total_height_high);
    m_qsettings->setValue(m_section + "/" + "total_width_low", total_width_low);
    m_qsettings->setValue(m_section + "/" + "total_width_high", total_width_high);
    m_qsettings->setValue(m_section + "/" + "m_ratio", m_ratio);
}

bool MeasureElectrode::showDialog()
{
    Mat image_show = himageToMat(image_in);
    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image,"");
    return true;
}


